﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Basmus.DataStructures.Generic
{
	public static class EnumerableExtension
	{
		public static IEnumerable<TSource> AsEnumerable<TSource>(this TSource source)
		{
			yield return source;
		}
		public static IEnumerable<TSource> Separate<TSource>(this IEnumerable<TSource> source, TSource separator)
		{
			IEnumerator<TSource> sourceEnumerator = source.GetEnumerator();
			if (sourceEnumerator.MoveNext())
			{
				yield return sourceEnumerator.Current;
			}
			while (sourceEnumerator.MoveNext())
			{
				yield return separator;
				yield return sourceEnumerator.Current;
			}
		}

		public static Group<TKey, TElement> ToGroup<TKey, TElement>(this IEnumerable<TElement> elements, TKey key)
		{
			return new Group<TKey, TElement>(key, elements);
		}
		public static IEnumerable<TSource> Concat<TSource>(this IEnumerable<TSource> source, TSource addItem)
		{
			foreach (TSource item in source)
			{
				yield return item;
			}
			yield return addItem;
		}
	}
}
